package exchange.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IDEA
 * Author: LuoHengYi
 * Date: 2022/6/17
 * Time: 18:12
 * Direct类型的 Exchange 交换机
 */
public class SenDirectExchange {
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建链接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        //作用域，不同的业务可以分配不同的作用域 /order ，/message
        connectionFactory.setVirtualHost("/");

        Connection connection = connectionFactory.newConnection();
        //每个Channel代表一个会话任务,类似sqlsession
        Channel channel = connection.createChannel();

        String exchangeName="test_direct_exchange";
        String routingKey="test_direct_routingKey";


        String msg=" hello luo heng yi ....";


        channel.basicPublish(exchangeName,routingKey,null,msg.getBytes());

    }
}
